package org.example.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.example.common.R;
import org.example.entity.AddressBook;
import org.example.entity.Cabinets;
import org.example.service.CabinetsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * TODO 类描述
 *
 * @author shaoxuan.
 * @date 2024/1/14 21:07
 */
@RestController
@Api(tags = "外卖柜管理")
@RequestMapping("/cabinet")
@Slf4j
public class CabinetController {
    @Autowired
    private CabinetsService service;

    /**
     * 添加快递柜
     *
     * @param cabinets
     * @return
     */
    @ApiOperation(value = "添加外卖柜")
    @PostMapping("/add")
    public R<Cabinets> addAddress(@RequestBody Cabinets cabinets) {
        if (service.save(cabinets)) {
            return R.success(cabinets).setMsg("添加成功！");
        } else {
            return R.error("添加失败！");
        }
    }


    /**
     * 修改快递柜状态
     *
     * @param cabinets
     * @return
     */
    @ApiOperation(value = "修改快递柜状态 外卖柜位置、状态")
    @PutMapping("/update")
    public R<String> update(@RequestBody Cabinets cabinets) {
        if (service.updateById(cabinets)) {
            return R.success("修改成功");
        } else {
            return R.error("修改成功！");
        }
    }

    @ApiOperation(value = "查看所有外卖柜")
    @GetMapping("/all")
    public R<List<Cabinets>> getAll() {
        return R.success(service.list());
    }


//    @ApiOperation(value = "删除外卖柜")
//    @GetMapping("/all")
//    public R<List<Cabinets>> remove() {
//        return R.success(service.list());
//    }


}
